home *** CD-ROM | disk | FTP | other *** search
/ PCGUIA 127 / PC Guia 127.iso / Software / Produtividade / OpenOffice.org 2.0.1 / openofficeorg1.cab / TutorialOpen.xba < prev    next >
Extensible Markup Language  |  2005-09-26  |  3KB  |  96 lines

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
  3. <script:module xmlns:script="http://openoffice.org/2000/script" script:name="TutorialOpen" script:language="StarBasic">REM  *****  BASIC  *****
  4. Dim myOpenDialog As Object
  5. Dim oListBox As Object
  6. Dim files As Object
  7. Dim oUcb As Object
  8. Dim oListener As Object
  9.  
  10. Sub TutorialOpenMain
  11.     GlobalScope.BasicLibraries.LoadLibrary("Tools")
  12.     myOpenDialog = LoadDialog("Tutorials","TutorialOpenDialog")    
  13.     init()
  14.     myOpenDialog.Execute()    
  15. End Sub
  16.  
  17. Sub Init
  18.     On Local Error Goto NOFILE        
  19.         myOpenDialog.Title = "Tutorials"
  20.         oListBox = myOpenDialog.GetControl("ListBox")    
  21.         templatePath = GetPathSettings("Template",false, 0)
  22.         Dim tutorialPath As String
  23.         iPos = InStr(templatePath,"/")
  24.         if(iPos > 0) Then
  25.             tutorialPath = templatePath & "/tutorials"
  26.         Else
  27.             tutorialPath = templatePath & "\tutorials"
  28.         End If
  29.         oUcb = createUnoService("com.sun.star.ucb.SimpleFileAccess")    
  30.         files = oUcb.getFolderContents(tutorialPath,true)    
  31.         size  = Ubound( files() )    
  32.         Dim tempFiles(size) As String
  33.         tempCount = 0
  34.         For iCount = 0 To size 
  35.             completPath = files(iCount)
  36.             oDocInfo = CreateUnoService("com.sun.star.document.DocumentProperties")            
  37.             oDocInfo.Read(completPath)
  38.             sDocTitle = oDocInfo.Title
  39.             if(not isNull(sDocTitle) And len(sDocTitle) > 0) Then
  40.                 oListbox.additem(sDocTitle,0)
  41.                 tempFiles(tempCount) = completPath
  42.                 tempCount = tempCount + 1
  43.             End If
  44.         Next iCount
  45.         'printdbgInfo oListbox
  46.         size = oListbox.ItemCount - 1
  47.         Dim tempFiles2(size) As String
  48.         For iCount = 0 To size
  49.             tempFiles2(iCount)  = tempFiles(iCount)             
  50.         Next iCount
  51.         files() = tempFiles2()
  52.     Exit Sub    
  53.     NOFILE:
  54.     If Err <> 0 Then
  55.         Msgbox "No file found error!" & CHR(13) & "Path: ...\share\template\...\tutorials\"
  56.         myOpenDialog.model.Open.enabled = False
  57.     End If
  58. End Sub
  59.  
  60. Sub ItemSelected(oEvent)
  61.     On Local Error Goto NOFILE        
  62.         completPath = files(Ubound(files()) - oEvent.Selected)    
  63.         oTextField = myOpenDialog.GetControl("Label") 'TextField    
  64.         oTextField.setText("")
  65.         Dim NoArgs() as new com.sun.star.beans.PropertyValue    
  66.         oDocInfo = CreateUnoService("com.sun.star.document.DocumentProperties")
  67.         oDocInfo.Read(completPath)
  68.         sDocDescription = oDocInfo.Description
  69.         if(not isNull(sDocTitle) And len(sDocDescription) > 0) Then    
  70.             oTextField.setText(sDocDescription)    
  71.         Else
  72.             oTextField.setText("Not Description!!!.")        
  73.         End If
  74.     Exit Sub
  75.     NOFILE:
  76.     If Err <> 0 Then
  77.         Msgbox "Open file error!"
  78.     End If    
  79. End Sub
  80.  
  81. Sub OpenTutorial(aEvent)
  82.     completPath = files(Ubound(files()) - oListBox.getSelectedItemPos())    
  83.     Dim Args(2) as new com.sun.star.beans.PropertyValue
  84.     Args(1).Name = "MacroExecutionMode"
  85.     Args(1).Value = com.sun.star.document.MacroExecMode.ALWAYS_EXECUTE
  86.     Args(2).Name = "AsTemplate"
  87.     Args(2).Value = true
  88.  
  89.     StarDesktop.LoadComponentFromURL(completPath,"_default",0, Args())
  90.     myOpenDialog.endExecute()
  91. End Sub
  92.  
  93. Sub Cancel(aEvent)
  94.     myOpenDialog.endExecute()
  95. End Sub
  96. </script:module>